home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #42 (Mar 89) / string width
Text File  |  1989-02-14  |  2KB  |  79 lines

  1. {$R-}
  2.  
  3. (*
  4.     strWidth -- a sample HyperCard external command
  5.                 that gets the width of a string.
  6.                 
  7.                 Written in MPW Pascal.
  8.                 Written by Fred Stauder
  9.                 MacTutor 1989
  10.  
  11. pascal :Sources:XCMD:strWidth.p 
  12. link -o AJS:test -rt XCMD=7002 -sn ∂
  13. Main=strWidth :Sources:XCMD:strWidth.p.o ∂
  14. {MPW}PLibraries:PasLib.o -m ENTRYPOINT    
  15.  
  16. *)
  17.  
  18. {$S strWidth }     { Segment name must be same as command name. }
  19.  
  20. UNIT Fred_Stauder;
  21.  
  22. INTERFACE
  23.  
  24. USES MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, PasLibIntf, HyperXCmd;
  25.  
  26. PROCEDURE ENTRYPOINT(paramPtr:XCmdPtr);
  27.  
  28. IMPLEMENTATION
  29.  
  30. TYPE Str31 = String[31];
  31.  
  32. PROCEDURE strWidth(paramPtr:XCmdPtr);    FORWARD;
  33.  
  34.     PROCEDURE ENTRYPOINT(paramPtr:XCmdPtr);
  35.  
  36.         BEGIN
  37.             strWidth(paramPtr);
  38.         END;
  39.  
  40.         PROCEDURE strWidth(paramPtr:XCmdPtr);        
  41.     
  42.             VAR
  43.                 tempStr:        Str255;
  44.                 tempInt:        Integer;
  45.         
  46.         
  47. {$I XCmdGlue.inc } {includes the glue routines}
  48.  
  49.     PROCEDURE Error(errStr:Str255); {return an error message}
  50.     
  51.         BEGIN
  52.             paramPtr^.returnValue := PasToZero(errStr);
  53.             {put error into 'the result'}
  54.             EXIT(strWidth); {leave the XCMD}
  55.         END; {Error}    
  56.         
  57.     PROCEDURE ParamCheck;
  58.     
  59.         CONST     paramCount: Integer;
  60.         VAR     params:     Integer;
  61.         
  62.         BEGIN
  63.             params := paramPtr^.paramCount;
  64.             IF (params <> paramCount)
  65.             THEN Error('strWidth "String" or Container');
  66.         END; {ParamCheck}
  67.         
  68.     BEGIN {Main}
  69.         CheckParamCount;
  70.         ZeroToPas(paramPtr^.params[1]^,tempStr);
  71.         {get the first Param}
  72.         tempInt := StringWidth(tempStr) ; {get the width}
  73.         tempStr := NumToStr(tempInt);
  74.         paramPtr^.returnValue := PasToZero(tempStr);
  75.     END; {Main}
  76.     
  77. END. {strWidth}
  78.  
  79.